<!-- 用户反馈 -->
<template>
    <div >
        <div class='table-page-search-wrapper'>
            <a-form layout='inline'>
               <a-row :gutter='48'>
                    <a-col :md='16' :sm='24'>
                    </a-col>
                    <a-col :md='8' :sm='24'>
                        <a-form-item >
                            <a-button @click="getData" type='primary'>查询</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>  

        <a-table rowKey="id" :loading="isload" @change="handleTableChange" :columns="columns" :pagination="{ pageSize: 10, total: total ,showSizeChanger: true,pageSize: size}" :data-source="dataList"  size="small">
            <!-- <div slot="imgUrl" slot-scope="imgUrl" >
                <img v-if="imgUrl && imgUrl.substring(0,4) == 'http'" class="imgUrl" :src="imgUrl" alt="" @click="showImg(imgUrl)">
                <div v-else>-</div>
            </div> -->
            <template slot="imgUrl" slot-scope="imgUrl">
                <img class="imgUrl" v-if="imgUrl && imgUrl.split(',').length > 0 " :src="imgUrl.split(',')[0]" @click="showImg(imgUrl)" alt="">
                <div v-else>-</div>
            </template>
            <div slot="reply" slot-scope="reply" >
                <div v-if="reply">{{reply}}</div>
                <div v-else>-</div>
            </div>
            <template slot="operation" slot-scope="text, record">
                <div class="editable-row-operations">
                    <a-button type="link" @click="update(record)">回复</a-button>
                </div>
            </template>
        </a-table>

        <!-- 回复内容 -->
        <a-modal
            title="回复留言"
            :visible="visible"
            @ok="handleOk"
            :confirm-loading="confirmLoading"
            @cancel="visible = false"
            >
            <div>
                <a-form :label-col="{ span: 8 }" :wrapper-col="{ span: 14 }">
                    <a-form-item label="回复内容">
                        <a-input :autosize="{ minRows: 2, maxRows: 6 }" type="textarea" v-model="reply" placeholder="请输入回复内容" allow-clear></a-input>
                    </a-form-item>
                </a-form>
            </div>
        </a-modal>

        <!-- 表格图片预览 -->
        <a-modal :visible="previewImgVisible" :footer="null" @cancel="previewImgVisible = false">
            <a-carousel autoplay dots-class="slick-dots slick-thumb" arrows style="margin-bottom:60px">
                <div v-for="(img,i) in showImgs" :key="i">
                    <img :src="img" alt=""/>
                </div>
                <a slot="customPaging" slot-scope="props">
                    <img :src="getImgUrl(props.i)" />
                </a>
            </a-carousel>
        </a-modal>
    </div>
</template>

<script>
import { queryUserSuggest , updateUserSuggest } from '@/api/travel';
import { columns } from './table';
export default {
    data () {
        return {
            brandId: this.global.brandId,
            dataList: [],
            total: 0,
            isload: false,
            page: 1,
            size: 10,
            isload: false,
            columns,
            previewImgVisible: false,
            showImgs: [],
            confirmLoading: false,
            isAdd: true,
            visible: false,
            reply: '',
        };
    },
    async created(){
        try {
            this.getData()
        } catch (error) {
            this.$notification['error']({
                message: '提示',
                description: error,
                duration: 8,
            })
        }
    },
    methods: {
        // 获取用户反馈信息
        getData(){
            var _this = this
            console.log(_this.page,'_this.page - 1')
            _this.isload = true
            const params = {
                'brandId': _this.brandId,
                'size':_this.size,
                'page':_this.page - 1,
            }
            queryUserSuggest(params)
            .then(res=>{
                _this.isload = false
                if(res.success){
                    _this.dataList = res.data.content
                    _this.total = res.data.totalElements
                    console.log(_this.dataList,'dataList')
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
        // 预览图片
        showImg(imgs){
            if(imgs){
                this.showImgs = imgs.split(',')
                console.log(this.showImgs,'imgs')
                this.previewImgVisible = true
            }
        },
        getImgUrl(i){
            return this.showImgs[i]
        },
        // 回复
        update(item){
            this.item = JSON.parse(JSON.stringify(item));
            this.reply = ''
            this.visible = true;
        },
        // 确认回复
        handleOk(){
            let _this = this;
            if(_this.reply == ''){
                _this.$message.warning('请输入回复内容')
                return;
            }
            const params = {
                'id': _this.item.id,
                'reply': _this.reply,
            }
            updateUserSuggest(params)
            .then(res => {
                if(res.success){
                    _this.getData();
                    _this.visible = false;
                    _this.$notification['success']({
                        message: '提示',
                        description: '回复成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
    }
}

</script>
<style scoped>
.imgUrl{
    width: 120px;
    height: 60px;
}
.ant-carousel >>> .slick-slide img {
    text-align: center;
    height: 300px;
    line-height: 300px;
    background: #364d79;
    overflow: hidden;
    width: 100%;
}
.ant-carousel >>> .slick-thumb {
  bottom: -15px;
}
.ant-carousel >>> .slick-thumb li {
  width: 60px;
  height: 45px;
}
.ant-carousel >>> .slick-thumb li img {
  width: 100%;
  height: 100%;
  filter: grayscale(100%);
}
.ant-carousel >>> .slick-thumb li.slick-active img {
  filter: grayscale(0%);
}
</style>